package com.htjc.uep.center.commons.aop.annotation;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import com.htjc.uep.center.commons.annotation.ExecuteTime;

/**
 * 执行时间切面
 * @author yao_xh
 */
@Aspect
@Component
public class ExecuteAspect {

	private Logger log = LoggerFactory.getLogger(this.getClass());
	/**
	 * 定义切点
	 */
	@Pointcut("execution(public * com.htjc..*.*(..))&&@annotation(executeTime)")
	public void executePointcut(ExecuteTime executeTime){};
	
	@Around("executePointcut(executeTime)")
	public Object executeTime(ProceedingJoinPoint joinPoint, ExecuteTime executeTime) throws Throwable {
		Long time = System.currentTimeMillis();
		Object obj = joinPoint.proceed();
		log.info("方法={}-执行结束-执行时间={}", joinPoint.getTarget().getClass().getSimpleName(), (System.currentTimeMillis() - time) + "ms");
		return obj;
	}
}
